package com.mk.settlement.task.impl;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.mk.settlement.service.SchedulerService;
import com.mk.settlement.service.SettlementRegularService;
import com.mk.settlement.task.SettlementTaskJob;

/**
 * 月结算计划任务服务类.
 * 
 * @author chuaiqing.
 *
 */
@Service(value="settlementMonthTaskJob")
public class SettlementMonthTaskJob implements SettlementTaskJob {

    /**
     * 注入月结算service
     */
    @Autowired
    @Qualifier(value="settlementMonthService")
    private SettlementRegularService monthService;
    
    @Autowired
    @Qualifier(value="schedulerService")
    private SchedulerService schedulerService;
    
    private static final String TASK_NAME = "月结定时任务";
    
    /**
     * 
     */
    @Override
    public void execute() {
        
        if(schedulerService.havePermission(TASK_NAME)) {
            
            log.info("月结  execute at: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
            // 生成月结算数据
            monthService.doSettlement();
        } else {
            
            log.info("没有获得" + TASK_NAME + "运行权限.");
        }
        
    }

}
